# -*- coding: UTF-8 -*-

import xlrd
from model import *
import sys
import numpy as np
import scipy.cluster.hierarchy as sch

# 获取shotsname
def get_shotsname(path):

    shotsname = []
    shotsID = set()

    for line in open(path):
        shot = str()
        ID = str()
        for char in line:
            if char != '.':
                shot += char
            else:
                break
        for char in line:
            if char != '_':
                ID += char
            else:
                break
        shotsname.append(shot)
        shotsID.add(ID)

    return shotsname, shotsID

# 读取excel,获取caselist
def get_caselist(path, shotsID, shotsname):

    workbook = xlrd.open_workbook(path)
    sheet1 = workbook.sheet_by_name('Sheet1')
    nrows = sheet1.nrows

    caselist = []

    def get_ID(shotname):
        ID = str()
        for char in shotname:
            if char != '_':
                ID += char
            else:
                break
        return ID

    for row in range(nrows):
        caseid = str(sheet1.cell_value(row, 4))
        caseid = caseid.replace('.0', '')
        for ID in shotsID:
            # if sheet1.cell_value(row, 0) == 1 and sheet1.cell_value(row, 1) == 1 :
                if ID == caseid:
                    newcase = case(int(ID))
                    newcase.bugdetails = sheet1.cell_value(row, 14)
                    for shot in shotsname:
                        if get_ID(shot) == ID:
                            newcase.screenshotslist.append(shot)
                    caselist.append(newcase)

    return caselist

shotsname, shotsID = get_shotsname('Data_2/AGJ/ImageNames-AGJ.txt')
caselist = get_caselist('Data_2/AGJ/AGJ.xls', shotsID, shotsname)






